layui.use(['jquery', 'form', 'layer'], function() {
	var
		$ = layui.$,
		form = layui.form,
		layer = layui.layer;

	form.verify({
		username: function(value) {
			if(value.length < 2) {
				return '用户名至少2位哦';
			}
		},
		password: [/^[A-Za-z0-9]{6,16}$/, '密码不符合规定哦'],
		content: function(value) {
			layedit.sync(editIndex);
		}
	});

	form.on('submit(login)', function(data) {
		// console.log(data.field);
		$.get(
			"../../../mock/login.json", {
				"username": username.value,
				"password": password.value
			},
			function(result) {
				for(var i = 0; i < result.data.length; i++) {
					if(result.data[i].username == username.value && result.data[i].password == password.value) {
						window.location.href = "../../pages/home/main.html";
						var realname = result.data[i].realname;
						var rolename = result.data[i].rolename;
						localStorage.setItem("realname", realname);
						localStorage.setItem("rolename", rolename);
					} else {
						layer.msg("该用户无效，请重新登录");
					}
				}
			},
			"json"
		);
		return false;
	});
});